﻿@model Sheng.WeixinConstruction.Management.Shell.Models.DockingViewModel

@{
    ViewBag.MainMenu = "Settings";
    ViewBag.LeftMenu = "Docking";

    ViewBag.Title = "微信对接";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<style type="text/css">

</style>

<script type="text/javascript">

    $(document).ready(function ()
    {


    });

    function docking()
    {
        var loadLayerIndex = layer.load(0, {
            shade: [0.2, '#fff']
        });

        $.ajax({
            url: "/Api/Settings/GetPreAuthCode",
            type: "POST",
            dataType: "json",
            success: function (data, status, jqXHR)
            {
                if (data.Success)
                {
                    var url = String.format("https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid={0}&pre_auth_code={1}&redirect_uri={2}",
                        data.Data.AppId, data.Data.PreAuthCode, "http://wxcm.shengxunwei.com/Settings/AuthorizationCallback");
                    window.location.href = url;

                } else
                {
                    layer.close(loadLayerIndex);
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest)
            {
                layer.close(loadLayerIndex);
                alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

    function update()
    {
        var loadLayerIndex = layer.load(0, {
            shade: [0.2, '#fff']
        });

        $.ajax({
            url: "/Api/Settings/UpdateAuthorizerAccountInfo",
            type: "POST",
            dataType: "json",
            success: function (data, status, jqXHR)
            {
                if (data.Success)
                {
                    location.reload();

                } else
                {
                    layer.close(loadLayerIndex);
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest)
            {
                layer.close(loadLayerIndex);
                alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

</script>





@if (Model.Authorizer == null)
{
    <div id="divStartDocking">
        <div style=" margin-top:20px; margin-left:10px; margin-right:10px; line-height:180%;" class="font_black_14">
            本系统是经过腾讯公司认证的，正规可靠的第三方运营平台。<br />
            请首先确保您的公众号是 <b>经过微信认证的服务号</b>，才能在对接后正常使用全部功能。<br>
            如果还没有微信公众号，请前往微信公众平台(<a href="https://mp.weixin.qq.com/" target="_blank">mp.weixin.qq.com</a>)进行注册。
        </div>

        <div style="margin-top:20px; background-color:#F6F6F6; padding-top:25px; padding-bottom:25px;">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td height="120" align="center"><img src="/Content/Images/docking_ico1.gif" width="98" height="98"></td>
                    <td align="center"><img src="/Content/Images/docking_ico2.gif" width="98" height="98"></td>
                    <td align="center"><img src="/Content/Images/docking_ico3.gif" width="98" height="98"></td>
                </tr>
                <tr>
                    <td height="40" align="center" class="font_black_24">微信官方许可</td>
                    <td align="center" class="font_black_24">公众号免繁琐设置</td>
                    <td align="center" class="font_black_24">安全可靠</td>
                </tr>
                <tr>
                    <td height="30" align="center" class="font_gray_15">腾讯公司审核认证的可靠平台</td>
                    <td align="center" class="font_gray_15">一键对接，轻松快捷</td>
                    <td align="center" class="font_gray_15">本系统不会也无法获取您的密码</td>
                </tr>
            </table>
        </div>

        <div align="center" style="margin-top:30px;">
            <img src="/Content/Images/docking_btn.jpg" width="367" height="62" onclick="docking()" style="cursor:pointer">
        </div>

    </div>
}
else
{
    <div id="divDockingInfo">
        <div style=" margin-top:20px; margin-left:10px; margin-right:10px; line-height:180%;" class="font_black_14">
            您已完成微信对接。<br />
            注意：原微信后台中设置的菜单及自动回复都已失效，请在本系统中重新设置。若要修改您的公众号信息，请登陆微信后台修改后，点击"刷新"按钮。<br>
            @if (Model.Authorizer.ServiceType != 2)
            {
                @:您的公众号不是服务号，只有<b>经过微信认证的服务号</b>，才能在对接后正常使用全部功能。<br>
            }
        </div>
        <div style=" margin-top:15px;">
            <div style="float:right">
                <input name="btnSave" type="button" class="btn_blue" id="btnStep2Next" value="刷 新" onclick="update()" />
            </div>
            <div style="clear:both"></div>
        </div>

        <div style="margin-top:20px;" class="font_black_14">
            <table width="100%" border cellpadding="5" cellspacing=0 bordercolor="#E0E0E0" rules=rows>
                <tr bordercolor="#E0E0E0">
                    <td width="5" valign="middle" bgcolor="#EEEEEE">&nbsp;</td>
                    <td width="120" height="26" valign="middle" bgcolor="#EEEEEE">公开信息</td>
                    <td valign="middle" bgcolor="#EEEEEE">&nbsp;</td>
                </tr>
                <tr bordercolor="#E0E0E0">
                    <td valign="middle">&nbsp;</td>
                    <td height="26" valign="middle">头像</td>
                    <td valign="middle">
                        <img src="@Model.Authorizer.HeadImg" style="width:96px; height:96px;" />
                    </td>
                </tr>
                <tr bordercolor="#E0E0E0">
                    <td valign="middle">&nbsp;</td>
                    <td height="26" valign="middle">二维码</td>
                    <td valign="middle">
                        <img src="@Model.Authorizer.QRCodeUrl" style="width:96px; height:96px;" />
                    </td>
                </tr>
                <tr bordercolor="#E0E0E0">
                    <td valign="middle">&nbsp;</td>
                    <td height="26" valign="middle">名称</td>
                    <td valign="middle">@Model.Authorizer.NickName</td>
                </tr>
                <tr bordercolor="#E0E0E0">
                    <td valign="middle">&nbsp;</td>
                    <td height="26" valign="middle">微信号</td>
                    <td valign="middle">@Model.Authorizer.Alias</td>
                </tr>
                <tr bordercolor="#E0E0E0">
                    <td valign="middle">&nbsp;</td>
                    <td height="26" valign="middle">类型</td>
                    <td valign="middle">@Model.Authorizer.ServiceTypeString</td>
                </tr>
                <tr bordercolor="#E0E0E0">
                    <td valign="middle">&nbsp;</td>
                    <td height="26" valign="middle">认证情况</td>
                    <td valign="middle">@Model.Authorizer.VerifyTypeString</td>
                </tr>
                <tr bordercolor="#E0E0E0">
                    <td valign="middle">&nbsp;</td>
                    <td height="26" valign="middle">原始ID</td>
                    <td valign="middle">@Model.Authorizer.UserName</td>
                </tr>
            </table>
        </div>


    </div>
}

@if (Model.UndockingAuthorizerList != null && Model.UndockingAuthorizerList.Count > 0)
{

    <div style="margin-top:30px;">
        您已经取消了以下公众号的授权对接：
    </div>

    <div style="margin-top:20px;" class="divBorder_lightgray">
        <table width="100%" border="0" cellpadding="10" cellspacing="0">
            <tr>
                <td width="100" bgcolor="#EEEEEE">头像</td>
                <td width="100" bgcolor="#EEEEEE">二维码</td>
                <td width="200" bgcolor="#EEEEEE">名称</td>
                <td width="150" bgcolor="#EEEEEE">类型</td>
                <td bgcolor="#EEEEEE">&nbsp;</td>
            </tr>
            @foreach (var item in Model.UndockingAuthorizerList)
            {
                <tr>
                    <td valign="middle">
                        <img src="@item.HeadImg" style="width:96px; height:96px;" />
                    </td>
                    <td valign="middle">
                        <img src="@item.QRCodeUrl" style="width:96px; height:96px;" />
                    </td>
                    <td valign="middle">@item.NickName</td>
                    <td valign="middle">@item.ServiceTypeString</td>
                    <td>&nbsp;</td>
                </tr>
            }
        </table>

    </div>

}